package com.bole.controller;


import com.bole.dto.order.TbOrderDto;
import com.bole.pojo.TbOrderDo;
import com.bole.service.CarService;
import com.bole.service.OrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.Data;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("order")
@Api(value = "订单管理api")
public class OrderController {

    @Autowired
    private OrderService orderService;

    @Autowired
    private CarService carService;


    @PostMapping("saveOrder")
    @ApiOperation(value = "生成订单",notes = "生成订单")
    @ApiImplicitParam(name = "orderDo",value = "生成订单",required = true,dataTypeClass = TbOrderDo.class)
    public TbOrderDto saveOrder(@RequestParam("carId") Long carId,@RequestBody TbOrderDo order) {
        TbOrderDo orderDo = orderService.save(carId,order);
        TbOrderDto orderDto = new TbOrderDto();
        BeanUtils.copyProperties(orderDo,orderDto);
        return orderDto;
    }

    //通过订单号查询
    @PostMapping("selectById")
    @ApiOperation(value = "生成订单",notes = "生成订单")
    @ApiImplicitParam(name = "id",value = "订单Id",required = true,dataTypeClass = Long.class)
    public TbOrderDto selectById(@RequestParam("id") Long id) {
        TbOrderDo orderDo = orderService.findById(id);
        TbOrderDto orderDto = new TbOrderDto();
        BeanUtils.copyProperties(orderDo,orderDto);
        return orderDto;
    }

    @PostMapping("updateOrder")
    @ApiOperation(value = "修改订单",notes = "修改订单")
    @ApiImplicitParam(name = "order",value = "修改订单",required = true,dataTypeClass = TbOrderDo.class)
    public TbOrderDto updateOrder(@RequestBody TbOrderDo order) {
        TbOrderDo orderDo = orderService.updateOrder(order);
        TbOrderDto orderDto = new TbOrderDto();
        BeanUtils.copyProperties(orderDo,orderDto);
        return orderDto;
    }

}
